Josephus — An OCaml Solution

OCaml has a nice circular data structure module, Dllist; it makes the solution trivial:

(* return number of survivor *)
let josephus n m =
  let rec j circle =
    if Dllist.length circle = 1
    then Dllist.get circle
    else j (Dllist.drop (Dllist.skip circle (m-1)))
  in
    j (Dllist.of_list (1--n))
val josephus : int -> int -> int = <fun>
# josephus 40 3;;
- : int = 28
# josephus 41 3;;
- : int = 31
#